<template>
  <div class="container">
    <div class="title">
      <h2>资讯分类</h2>
      <h5>用于展示小区里每一栋的基础信息</h5>
    </div>
    <!-- 表格 -->
    <el-card class="tableCard">
      <el-button
        style="float: right; padding: 10px 20px; margin-right: 80px"
        type="primary"
        size="small"

        @click="$refs.addForm.dialogShow = true"
      >新增项目</el-button>
      <el-table :data="list" style="width: 100%">
        <el-table-column prop="id" label="ID" />
        <el-table-column prop="catename" label="分类名" />
        <el-table-column fixed="right" label="操作">
          <template slot-scope="{row}">
            <el-button
              type="text"
              size="small"
              :disabled="!checkBtnPermission('/content/cate','update')"
              @click="handleClick(row.id)"
            >编辑</el-button>
            <el-button
              type="text"
              size="small"
              :disabled="!checkBtnPermission('/content/cate','destroy')"
              @click="delRow(row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <!-- 页面渲染 -->
      <!-- 分页 -->
      <el-row type="flex" justify="end">
        <el-pagination
          :page-sizes="[5,10, 15, 20, 30]"
          :page-size="formData.pageSize"
          :current-page="formData.current"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </el-row>
    </el-card>
    <!-- 新增、修改弹框区域 -->
    <addForm ref="addForm" @updataList="initData" />
  </div>
</template>

<script>
import { contentInfo, ContentInfoId } from '@/api/content/content_cate'
import addForm from './components/cateForm.vue'
export default {
  name: 'Building',
  components: {
    addForm
  },

  data() {
    return {
      formData: {
        current: 1,
        pageSize: 10,
        catename: ''

      }, // 表单
      count: 0,
      list: [] // 获取列表
    }
  },
  created() {
    this.initData()
  },

  methods: {
    // 数据渲染
    async initData() {
      const { data } = await contentInfo(this.formData)
      console.log('initData  data:', data.data)
      this.list = data.data.rows
      this.count = data.data.count
    },
    // 编辑
    async handleClick(rowId) {
      // 获取改行的数据
      // console.log(11)
      const { data } = await ContentInfoId(rowId)
      console.log(data.data)
      // 赋给弹框里面的表单
      // console.log(this.$refs.addForm.quartData)
      this.$refs.addForm.quartData = data.data
      // console.log('editRow  res:', data.data)
      // 复杂点：一些负责的表单控件需要手动去回显
      // 打开弹框
      this.$refs.addForm.dialogShow = true
    },
    // // 删除
    // async delRow(rowId) {
    //   console.log('1111', rowId)
    //   // 弹出确认框
    //   await this.$confirm('确认删除吗')
    //   // 发生删除请求
    //   const { data } = await delHouseInfo(rowId)
    //   // 提示成功
    //   // console.log(data.success)
    //   if (!data.success) {
    //     return this.$message.error(data.msg)
    //   }
    //   this.$message.success('删除成功')
    //   // 列表更新
    //   this.initData()
    // },
    // 点击切换页数
    handleCurrentChange(val) {
      this.formData.current = val
      this.initData()
    },

    // 点击切换数量
    handleSizeChange(val) {
      this.formData.pageSize = val
      this.initData()
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 40px;
  .title {
    display: flex;
    align-items: center;
    h2 {
      margin-right: 20px;
    }
    h5 {
      font-weight: 400;
      color: #9c9c9d;
      vertical-align: middle;
    }
  }
  .demo-form-inline {
    display: flex;
  }
  .el-form-item {
    margin-right: 73px;
  }
  .btn {
    padding-top: 40px;
  }
  .box-card {
    margin-bottom: 10px;
  }
}

.block{
  margin-top: 30px;
  text-align: right;
}
</style>
